package com.yiwei.ydd.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.text.Spanned;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.yiwei.ydd.R;
import com.yiwei.ydd.api.model.CashBackListsModel;
import com.yiwei.ydd.util.Dialog;
import com.yiwei.ydd.util.Spans;

import butterknife.BindView;
import butterknife.ButterKnife;


/**
 * Created by xsooy-pc on 2017/10/23.
 */

public class RetrunCashGroupAdapter extends ItemAdapter<CashBackListsModel.DatasBean, RetrunCashGroupAdapter.DefaultHolder> {



    private Context context;
    private final int x26;
    private final int x22;

    public RetrunCashGroupAdapter(Context context) {
        super(context);
        this.context = context;
        x26 = context.getResources().getDimensionPixelSize(R.dimen.x26);
        x22 = context.getResources().getDimensionPixelSize(R.dimen.x22);
    }

    @Override
    public DefaultHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        return new DefaultHolder(inflate(R.layout.item_group_packet_sec, parent));
    }

    @Override
    public void onBindViewHolder(DefaultHolder holder, int position) {
        CashBackListsModel.DatasBean item = getItem(position);


        //订单状态（-2：失效，-1：失败，0：待支付，1：完成，2：已付款，3：加油中）
        String status = "";
        switch (item.status) {
            case "-2":
                status = "失效";
                break;
            case "-1":
                status = "失败";
                break;
            case "0":
                status = "待支付";
                break;
            case "1":
                status = "已完成";
                break;
            case "2":
                status = "已付款";
                break;
            case "3":
                status = "加油中";
                break;

        }
        holder.txtStatus.setText(status);

        Spanned name = Spans.with(context).font(item.name, x26, 0xff666666).
                font("（剩余" + item.last_back + "元未到账）", x22, 0xffFB5E01).
                build();
        holder.txtContent.setText(name);

        RetrunCashChildAdapter adapter = new RetrunCashChildAdapter(context);
        holder.listData.setAdapter(adapter);
        adapter.update(item.items);
        holder.btnTips.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Dialog.showDefaultDialog(context, "", "到账总额为加油套餐充值每月返现+加油包每个月返现的总额", "", "明白了", false, new Dialog.DialogDefaultClickListener() {
                    @Override
                    public void confirm() {

                    }

                    @Override
                    public void cancel() {

                    }
                });
            }
        });

        holder.txtContent.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (holder.listData.getVisibility() == View.VISIBLE) {
                    holder.listData.setVisibility(View.GONE);
                    holder.layoutTitle.setVisibility(View.GONE);
                    holder.txtStatus.setTextColor(0xff999999);
                    holder.imgSign.setImageResource(R.mipmap.img_cash_unselect);
                } else {
                    holder.listData.setVisibility(View.VISIBLE);
                    holder.txtStatus.setTextColor(0xffFB5E01);
                    holder.layoutTitle.setVisibility(View.VISIBLE);
                    holder.imgSign.setImageResource(R.mipmap.img_cash_select);


                }
            }
        });
    }

    class DefaultHolder extends RecyclerView.ViewHolder {
        @BindView(R.id.txt_content)
        TextView txtContent;
        @BindView(R.id.txt_status)
        TextView txtStatus;
        @BindView(R.id.view_bottom)
        View viewBottom;
        @BindView(R.id.btn_tips)
        ImageView btnTips;
        @BindView(R.id.layout_title)
        LinearLayout layoutTitle;
        @BindView(R.id.list_data)
        RecyclerView listData;
        @BindView(R.id.img_sign)
        ImageView imgSign;
        public DefaultHolder(View itemView) {
            super(itemView);
            ButterKnife.bind(this, itemView);
        }
    }
}
